/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	FBXUtility.h
*
*	Description -	Wrapper class for simplifying basic FBX methods.
*
*	Comments	-	A simple mesh to be used by the model exporter.
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	09/14/2012	-	Creation of this file
**************************************************************************************/

#ifndef _MESH_H_
#define _MESH_H_
#include "../Pulse-Tec/Include/Pulse.h"

namespace Pulse
{
	struct SubMesh
	{
		SubMesh( void );

		int indicesOffset;
		int numTriangles;
	};

	struct UVSet
	{
		typedef Array<Vector2> UVList;

		String name;
		UVList UVs;

	};

	struct Mesh
	{
	public:

		Mesh( void );

		~Mesh( void );

		const SIZE_T32 GetNumVertices( void ) const { return m_numVertices; }

		const SIZE_T32 GetNumSubMeshes( void ) const { return m_numSubMeshes; }

		const SIZE_T32 GetNumIndices( void ) const { return m_numIndices; }

		void ResizeSubMeshes( SIZE_T32 newSize );

		void ResizeVertices( SIZE_T32 newSize );

		void ResizeIndices( SIZE_T32 newSize );

		SubMesh * GetSubMesh( UPOS_T32 index );

		Vector3 * GetVertices( void ) { return m_pVertices; }

		UPOS_T32 * GetIndices( void ) { return m_pIndices; }

		// Adding other vertex elements
		void SetNormalsEnabled( BOOL bEnable );

		const BOOL IsNormalsEnabled( void ) const { return m_bHaveNormals; }

		Vector3 * GetNormals( void ) { return &m_normals[0]; } 

		const SIZE_T GetNumUVSets( void ) const { return m_UVSets.GetSize(); }

		void ResizeUVSets( SIZE_T32 newSize );

		UVSet * GetUVSet( UPOS_T32 index ) { return &m_UVSets[index]; }
		
		const UVSet * GetUVSet( UPOS_T32 index ) const { return &m_UVSets[index]; }

	private:

		void UpdateElements( void );

		// Update ELements calls these private members
		void UpdateNormalElement( void );
		void UpdateUVElement( void );

	private:

		typedef Array<Vector3> NormalList;
		typedef Array<UVSet> UVSetList;

		Vector3 *m_pVertices;
		SIZE_T32 m_numVertices;

		BOOL	m_bHaveNormals;
		NormalList m_normals;

		UVSetList	m_UVSets;

		UPOS_T32 *m_pIndices;
		SIZE_T32 m_numIndices;

		SubMesh *m_pSubMeshes;
		SIZE_T32 m_numSubMeshes;

	};
}

#endif /* _MESH_H_ */